package com.para.esc.timertask;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import java.util.UUID;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

public class LeaveTask extends TimerTask  {
	protected Log logger = LogFactory.getLog(this.getClass());

	private DataSource dataSource;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
		
	@Override
	public void run() {
		// TODO Auto-generated method stub

		logger.info("in LeaveTask!");
//		String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//		JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
//		
//		String queryEmployeeSql="select a.PR_ID as \"userId\" from PR_EMPLOYEE a where PR_LEAVEDATE='"+date+"'";
//		List<Map<String,Object>> list = jdbcTemplate.queryForList(queryEmployeeSql);
//		
//		
//		
//		for(Map map :list){
//			String userId = map.get("userId").toString();
//			
//			String queryResAccountSql="select a.PR_ID as \"resAcountId\",a.PR_RESID as \"resId\" from PR_RESACCOUNT a where PR_STATUS='1' and PR_USERID='"+userId+"'";
//			List<Map<String,Object>> list2 = jdbcTemplate.queryForList(queryResAccountSql);
//			for(Map map2 :list2){
//				
//				String id = UUID.randomUUID().toString().replaceAll("-", "");
////				map2.get("resAcountId");
////				map2.get("resId");
//				String insertSql="inset into PUSHACCOUNTTASK (ID,APPID,USERID,TYPE,ERRORTIME,ERRORMSG,STATE,RESACCID) values('"+id+"','"+map2.get("resId").toString()+"','"+userId+"','3',0,'0','0','"+map2.get("resAcountId").toString()+"'";
//				jdbcTemplate.update(insertSql);
//			}
//			String updateEmployee="update PR_EMPLOYEE set PR_STATUS=0 where PR_ID='"+userId+"'";
//			jdbcTemplate.update(updateEmployee);
//			
//		}
//		
		logger.info("end LeaveTask!");
		
	}

}
